Git CheatSheet 💻

CommandDescriptionHow to UseExample
git initInitializes a new Git repositorygit initgit init (inside the project folder)
git cloneCreates a local copy of a remote repositorygit clone <repo_url>git clone <https://github.com/user/repo.git>
git statusShows the status of changes in the working directorygit statusgit status
git addStages changes for the next commitgit add <file_or_directory>git add . (to stage all changes)
git commitCommits staged changes with a messagegit commit -m "<commit_message>"git commit -m "Initial commit"
git logDisplays the commit historygit loggit log --oneline (compact view of commits)
git diffShows differences between working directory and indexgit diffgit diff (shows unstaged changes)
git branchLists, creates, or deletes branchesgit branchgit branch feature-branch (to create a new branch)
git checkoutSwitches between branchesgit checkout <branch_name>git checkout master (switch to master branch)
git mergeMerges changes from one branch into anothergit merge <branch_name>git merge feature-branch
git pullFetches and merges changes from the remote repositorygit pullgit pull origin master
git pushPushes committed changes to a remote repositorygit push <remote> <branch_name>git push origin master
git remoteManages connections to remote repositoriesgit remote -vgit remote add origin <https://github.com/user/repo.git>
git fetchDownloads changes from a remote repository without merginggit fetch <remote>git fetch origin
git resetUnstages or resets changes to a previous commitgit reset <file> or git reset --hardgit reset --hard HEAD (resets all changes to the last commit)
git rmRemoves a file from the working directory and staging areagit rm <file>git rm file.txt
git stashTemporarily saves changes that aren’t ready for commitgit stashgit stash (saves changes)
git stash applyApplies the most recent stashgit stash applygit stash apply
git tagCreates a tag to mark specific commitsgit tag <tag_name>git tag v1.0.0
git showShows details about a specific commit or taggit show <commit/tag>git show v1.0.0
git log --graphDisplays commit history in a graph formatgit log --graphgit log --graph --oneline
git cherry-pickApplies the changes from a specific commit to the current branchgit cherry-pick <commit_hash>git cherry-pick a1b2c3d4
git rebaseReapplies commits on top of another base tipgit rebase <branch>git rebase master
git revertReverts a specific commit by creating a new commitgit revert <commit_hash>git revert a1b2c3d4
git blameShows which commits modified each line of a filegit blame <file>git blame README.md
git bisectFinds the commit that introduced a bug using binary searchgit bisect start / git bisect good <commit> / git bisect badStart a bisect search
git cleanRemoves untracked files from the working directorygit clean -fgit clean -f (forces removal of untracked files)
git configConfigures Git settings (username, email, etc.)git config <key> <value>git config --global user.name "John Doe"
git archiveCreates a zip or tarball of the repositorygit archive --format=zip HEAD > archive.zipgit archive --format=zip HEAD > archive.zip
git submoduleManages external repositories as submodulesgit submodule add <repo_url>git submodule add <https://github.com/user/submodule.git>
git reflogShows a log of all changes to the HEAD pointergit refloggit reflog
git ls-filesLists all the files being tracked by Gitgit ls-filesgit ls-files
git commit --amendModifies the last commitgit commit --amend -m "<new_message>"git commit --amend -m "Updated commit message"